################################################################################
# install packages
# devtools must be done first, requires Rtools 4.0.
install.packages("devtools",type = "win.binary")

install.packages("sf", type = "win.binary")
install.packages("ggplot2", type = "win.binary")
install.packages("DescTools", type = "win.binary")
install.packages("readr", type = "win.binary")
install.packages("pillar", type = "win.binary")
install.packages("dplyr", type = "win.binary")
install.packages("geometry", type = "win.binary")
install.packages("snow", type = "win.binary")
install.packages("matrixStats", type = "win.binary")
install.packages("reshape2", type = "win.binary")

# The following version of transport is compatible with R 4.0.5.
devtools::install_version("transport", version = "0.14-7", repos = "http://cran.us.r-project.org")
devtools:::install_github("jrive/Rgeogram")

# Note: I've linked to my forked version of Rgeogram to help reliably replicate. 
# Original version found at https://github.com/TraME-Project/Rgeogram

library(sf)         # includes set operations like intersection and polygon object
library(transport)  # used to generate power diagrams
library(geometry)   # used to quickly calculate areas of power diagram cells
library(snow)       # to parallelize
library(parallel)   # to parallelize
library(data.table) # cross join CJ()
library(ggplot2)    # visualization tools
library(Rcpp)       # run C++ code
library(Rgeogram)   # run C++ code from Geogram library for OT (Merigot [2011])
library(DescTools)  # Univariate Gini
library(matrixStats)# Column and row wise operations
library(MASS)
library(reshape2)
library(readr)

###############################################################################
# Functions 
source("functions/Lmap.R")        # Calculate Lorenz map values for ranks r
source("functions/ILF.R")         # Calculate ILF as the ecdf of Lorenz map values
source("functions/vquantile.R")   # Calculate the OT map 
source("functions/scaling.min.max.R") # Helpful to scale data into [0,1]^2
source("functions/eCDF.R")        # bivariate ecdf
